/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.wutu.nbyjk8.controller;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;
import com.wutu.nbyjk8.domain.DataJsonSourceManage;
import com.wutu.nbyjk8.mapper.DataJsonSourceManageMapper;
import com.wutu.nbyjk8.service.impl.DataJsonSourceManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据源管理Controller
 *
 * @author 朱欢乐
 * @version 2023-06-19
 */

@Api(tags = "json数据管理")
@RestController
@RequestMapping(value = "/datajsonsourcemanage/dataJsonSourceManage")
@Slf4j
@JsonIgnoreProperties(ignoreUnknown = true)
public class DataJsonSourceManageController extends BaseController {

    @Autowired
    private DataJsonSourceManageService dataJsonSourceManageService;

    @Autowired
    DataJsonSourceManageMapper dataJsonSourceManageMapper;

    @Autowired
    RestTemplate restTemplate;

    private Map<String, Object> map = new HashMap<>();


    /**
     * 数据源管理列表数据
     */
    @ApiOperation(value = "查询数据源管理列表数据")
    @GetMapping("list")
    public ResponseEntity<IPage<DataJsonSourceManage>> list(@RequestParam(value = "name", required = false) String name
          , Page<DataJsonSourceManage> page) throws Exception {
        QueryWrapper<DataJsonSourceManage> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(name)) {
            queryWrapper.like("name", name);
        }
        IPage<DataJsonSourceManage> result = dataJsonSourceManageService.page(page, queryWrapper);
        return ResponseEntity.ok(result);
    }


    /**
     * 根据Id获取数据源管理数据
     */
    @ApiOperation(value = "根据Id获取数据源管理数据")
    @GetMapping("queryById")
    public ResponseEntity<DataJsonSourceManage> queryById(String id) {
        return ResponseEntity.ok(dataJsonSourceManageService.getById(id));
    }

    /**
     * 保存数据源管理
     */
    @ApiOperation(value = "保存数据源管理")
    @PostMapping("save")
    public ResponseEntity<String> save(@RequestBody DataJsonSourceManage dataSourceManage) {
        //新增或编辑表单保存
        dataJsonSourceManageService.saveOrUpdate(dataSourceManage);
        return ResponseEntity.ok("保存数据源管理成功");
    }


    /**
     * 删除数据源管理
     */
    @ApiOperation(value = "删除数据源管理")
    @DeleteMapping("delete")
    public ResponseEntity<String> delete(String ids) {
        String idArray[] = ids.split(",");
        dataJsonSourceManageService.removeByIds(Lists.newArrayList(idArray));
        return ResponseEntity.ok("删除数据源管理成功");
    }
}
